define(['app'], function(app) {
    'use strict';

    // 实例化方法
    var factory = function(Http) {
        /**
         * 一键切换数据获取方式
         *@param {Object} result
         */
        function get_data_getlist(result) {
            if(HTTP_ISLOGIC) {
                result = '{"success":true,"msg":"","result":{"act_id": "001","name":"团购","abstract":"这样是什么鬼啊真的看到不懂啊","start_time":"2017/01/01 09:00:00","end_time":"2017/01/31 09:00:00","apply_end_time":"2017/21/31 09:00:00","create_group": true,"has_packets":true,"brand_id": "001","cat_type_id": "001","goods_id":"001","goods_name":"一字螺丝刀","image":"001.jpg","mktprice":11,"price":5,"count":100,"paper":{"paper_id":"001","questions":[{"id":"001","question": "问题1","answer": [{"id": "1","choose_no":"A","data":"答案1"},{"id":"2","choose_no":"A","data":"答案2"}],"right_no":"A"},{"id":"002","question":"问题2","answer":[{"id":"1","choose_no":"A","data":"答案1"},{"id":"2","choose_no":"A","data":"答案2"}],"right_no":"A"}]}},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
                return JSON.parse(result);
            } else {
                return result;
            }
        }
        //商品检索
        function get_data_goods_list(result) {
            if(HTTP_ISLOGIC) {
                result = '{"success":true,"msg":"","result":{"store_count":"500","goods":[{"goods_id":"001","name":"十字螺丝刀","introduce":"十字螺丝刀","price":10.5,"mktprice":11,"preprice":10,"store_id":"WuJin_1","store_name":"五金一店","image":{"id":1,"image":"img/upload/pro-img01.jpg"},"store":1234,"cat_type_name":"工具-小型工具-螺丝刀"},{"goods_id":"002","name":"一字螺丝刀","introduce":"一字螺丝刀","price":10.5,"mktprice":11,"preprice":10,"store_id":"WuJin_1","store_name":"五金一店","image":{"id":2,"image":"img/upload/pro-img01.jpg"},"store":1000,"cat_type_name":"工具-小型工具-螺丝刀"},{"goods_id":"003","name":"扳手","introduce":"好扳手","price":5.5,"mktprice":8,"preprice":5,"store_id":"WuJin_1","store_name":"五金一店","image":{"id":2,"image":"img/upload/pro-img01.jpg"},"store":1000,"cat_type_name":"工具-小型工具-螺丝刀"},{"goods_id":"004","name":"活动扳手","introduce":"好活动扳手","price":5.5,"mktprice":8,"preprice":5,"store_id":"WuJin_1","store_name":"五金一店","image":{"id":2,"image":"img/upload/pro-img01.jpg"},"store":1000,"cat_type_name":"工具-小型工具-螺丝刀"}],"page":[{"limit":8,"tPage":5,"cPage":1,"count":4}]},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
                return JSON.parse(result);
            } else
                return result
        }

        function get_data_edit(result) {
            if(HTTP_ISLOGIC) {
                result = '{"success":true,"msg":"","result":{"act_id":"001"},"session":"7311da98bd0f18eb15a96bcb263f4153"}';
                return JSON.parse(result);
            } else {
                return result;
            }
        }

        // 返回信息
        return {
            //获得新品赠送活动的详细
            getlist: function(act_id, callback) {
                Http.post({
                        method: 'marketing.giving.detail',
                        session: '',
                        act_id: act_id
                    },
                    function(result) {
                        //请求成功
                        if(callback) {
                            callback(get_data_getlist(result).result);
                        }
                    },
                    function(e) {
                        //请求异常
                    },
                    function() {
                        //请求完成，一般不做什么事情
                    });

            },
            //编辑
            edit: function(act_id, name,abstract, start_time, end_time, apply_end_time, brand_id, cat_type_id, goods_id, price, count, paper, callback) {
                Http.post({
                        method: 'marketing.giving.createedit',
                        updateParams: {
                            act_id: act_id,
                            name: name,
                            abstract:abstract,
                            start_time: start_time,
                            end_time: end_time,
                            apply_end_time: apply_end_time,
                            brand_id: brand_id,
                            cat_type_id: cat_type_id,
                            goods_id: goods_id,
                            price: price,
                            count: count,
                            paper: paper
                        }
                    },
                    function(result) {
                        if(callback)
                            callback(get_data_edit(result));
                    },
                    function(e) {
                        //请求异常
                    },
                    function() {
                        //请求完成，一般不做什么事情
                    });

            },
            //检索商品获取
            goods_list: function(cat_type, name, brand_id, callback) {
                Http.post({
                    method: 'goods.common.getlist',
                    cat_type: cat_type,
                    paglimit: 8,
                    nPage: 1,
                    show_count: 5,
                    brand_id: brand_id,
                    picSize: 'CS',
                    name: name
                }, function(result) {
                    if(callback)
                        callback(get_data_goods_list(result).result);
                }, function(e) {

                }, function() {

                })
            },

        };
    }

    factory.$inject = ['Http'];
    return app.registerService("Give", factory);
});